package com.wumeng.interview.adapter;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.TextView;
import android.widget.Toast;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.wumeng.interview.R;
import com.wumeng.interview.bean.RecordBean;
import com.wumeng.interview.util.ContextHolder;

import java.util.List;

/**
 * @Time : 2021/8/8
 * @Author : Wu-Meng
 * @Description :
 */
public class SecondRecyclerAdapter extends RecyclerView.Adapter<SecondRecyclerAdapter.ViewHolder>{

    private List<RecordBean> recordBeanList;

    public SecondRecyclerAdapter(List<RecordBean> recordBeanList) {
        this.recordBeanList = recordBeanList;
    }

    @NonNull
    @Override
    public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.layout_item_second_recycler_view,parent,false);
        return new ViewHolder(view);
    }

    @Override
    public void onBindViewHolder(@NonNull ViewHolder holder, int position) {
        RecordBean bean = recordBeanList.get(position);
        holder.textView.setText(bean.getValue());
        holder.textView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Toast.makeText(ContextHolder.getContext(),bean.getValue(),Toast.LENGTH_LONG).show();
            }
        });
    }

    @Override
    public int getItemCount() {
        return recordBeanList != null ? recordBeanList.size() : 0;
    }

    static class ViewHolder extends RecyclerView.ViewHolder {

        private TextView textView;

        public ViewHolder(@NonNull View itemView) {
            super(itemView);
            textView = itemView.findViewById(R.id.btn);
        }
    }

}
